/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__cups_get_currency.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include <cups/cups_core.h>
#include <cups/cups_comm.h>
#include <apmtest_comm.h>
#include <cups/config.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("1");

    i_ret = cups_get_currency(&p_value, 0);

    CU_ASSERT_STRING_EQUAL(p_value, "1");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

static void __case2(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("1");

    i_ret = cups_get_currency(&p_value, 1);

    CU_ASSERT_STRING_EQUAL(p_value, "0.1");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

static void __case3(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("1");

    i_ret = cups_get_currency(&p_value, 2);

    CU_ASSERT_STRING_EQUAL(p_value, "0.01");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

static void __case4(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("1");

    i_ret = cups_get_currency(&p_value, 3);

    CU_ASSERT_STRING_EQUAL(p_value, "0.001");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

static void __case5(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("1");

    i_ret = cups_get_currency(&p_value, 4);

    CU_ASSERT_STRING_EQUAL(p_value, "0.0001");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

static void __case6(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("000000100002");

    i_ret = cups_get_currency(&p_value, 2);

    CU_ASSERT_STRING_EQUAL(p_value, "1000.02");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

static void __case7(void)
{
    int i_ret = FR_SUCC;
    char *p_value = frstrdup("000000100002");

    i_ret = cups_get_currency(&p_value, 0);

    CU_ASSERT_STRING_EQUAL(p_value, "100002");
    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    frfree(p_value);

    return;
}

int add_suite_cups_get_currency(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" cups_get_currency()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL
        )
        return FR_FAIL;

    return FR_SUCC;
}
